package com.voltmao.webpro.utils.wechat;

import com.voltmao.webpro.utils.wechat.utils.MenuUtils;
import com.voltmao.webpro.utils.wechat.utils.menu.EventType;
import com.voltmao.webpro.utils.wechat.utils.menu.MenuNode;
import com.voltmao.webpro.utils.wechat.utils.menu.MenuParent;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * Created by zhouyang on 2017/1/6.
 */
public class WxMenu {

    public synchronized static void main(String[] args) throws UnsupportedEncodingException {
        UserCarWXMenu("usercar");
//          UserCarWXMenu("testusercar");
//        ServiceAddWXMenu("serviceadd");
    }

    /**
     * 车主端
     */
    public static void UserCarWXMenu(final String appName) throws UnsupportedEncodingException {
        final WechatUtils wechatUtils = WechatUtils.getInstance(appName);
        MenuUtils menuUtils = wechatUtils.getMenuUtils();

        menuUtils.createMenu(new MenuUtils.MenuInterface() {
            @Override
            public void addRootMenu(List<Object> rootMenus) {
                MenuNode rootMenu3 = new MenuNode();
                rootMenu3.setName("绑定设备");
                rootMenu3.setType(EventType.view);
                rootMenu3.setUrl(wechatUtils.builderAuthUrl("api/system/rearview/load/rearviewBind.html?appType=" + appName));
                rootMenu3.setType(EventType.view);

//                MenuNode rootMenu4 = new MenuNode();
//                rootMenu4.setName("发布广告");
//                rootMenu4.setType(EventType.view);
//                rootMenu4.setUrl(wechatUtils.builderAuthUrl("pages/usercarapp/rearviewload/index.jsp?appType=" + appName));
//                rootMenu4.setType(EventType.view);
                MenuParent menuParent = new MenuParent();
                menuParent.setName("广告");
                menuParent.setSub_button(new MenuNode[]{rootMenu3});

                MenuNode f2Node = new MenuNode();
                f2Node.setName("商城");
                f2Node.setType(EventType.click);
                f2Node.setKey("uplv");

                MenuNode rw_ct_Node = new MenuNode();
                rw_ct_Node.setName("发布广告");
                rw_ct_Node.setType(EventType.view);
                rw_ct_Node.setUrl(wechatUtils.builderAuthUrl("pages/usercarapp/rearviewload/index.html?appType=" + appName));
//
                MenuNode myInfoPage = new MenuNode();
                myInfoPage.setName("个人中心");
                myInfoPage.setUrl(wechatUtils.builderAuthUrl("api/usercarapp/myInfo.html?appType=" + appName));
                myInfoPage.setType(EventType.view);

                MenuNode tx = new MenuNode();
                tx.setName("余额提现");
//                myInfoPage.setUrl(wechatUtils.builderAuthUrl("pages/usercarapp/myinfo/main.jsp?appType=" + appName));
                tx.setType(EventType.click);
                tx.setKey("1002");

                MenuNode jf = new MenuNode();
                jf.setName("每日积分");
//                myInfoPage.setUrl(wechatUtils.builderAuthUrl("pages/usercarapp/myinfo/main.jsp?appType=" + appName));
                jf.setType(EventType.click);
                jf.setKey("1001");

                MenuParent p3 = new MenuParent();
                p3.setName("我");
                p3.setSub_button(new MenuNode[]{jf, tx, myInfoPage});
//                rootMenus.add(rw_ct_Node);
//                rootMenus.add(myInfoPage);

                MenuNode p_node3 = new MenuNode();
                p_node3.setName("正在升级");
                p_node3.setType(EventType.click);
                p_node3.setKey("uplv");

                rootMenus.add(menuParent);
                rootMenus.add(f2Node);
                rootMenus.add(p3);
            }
        });
    }


    public static void ServiceAddWXMenu(final String appName) throws UnsupportedEncodingException {
        final WechatUtils wechatUtils = WechatUtils.getInstance(appName);

        MenuUtils menuUtils = wechatUtils.getMenuUtils();
        menuUtils.createMenu(new MenuUtils.MenuInterface() {
            @Override
            public void addRootMenu(List<Object> rootMenus) {

                MenuNode cz = new MenuNode();
                cz.setName("充值");
                cz.setUrl(wechatUtils.builderAuthUrl("pages/serviceaddapp/looks.wechat.webpro/cqMoney.jsp?appType=" + appName + "&toUrl=myInfo"));
                cz.setType(EventType.view);

                MenuNode myInfoMenu = new MenuNode();
                myInfoMenu.setName("我的");
                myInfoMenu.setUrl(wechatUtils.builderAuthUrl("pages/serviceaddapp/looks.wechat.webpro/myinfo.jsp?appType=" + appName + "&toUrl=myInfo"));
                myInfoMenu.setType(EventType.view);


//                MenuNode rootMenu2 = new MenuNode();
//                rootMenu2.setName("后视镜绑定");
//                rootMenu2.setUrl(wechatUtils.builderAuthUrl("api/serviceaddapp/loginAndToUrl.html?appType=" + appName + "&toUrl=rearviewBind"));
//                rootMenu2.setType(EventType.view);
//
//                MenuParent blywMenu = new MenuParent();
//                blywMenu.setName("办理业务");
//                blywMenu.setSub_button(new MenuNode[]{rootMenu2});

                rootMenus.add(cz);
                rootMenus.add(myInfoMenu);
            }
        });

    }

}
